package com.example.it.studyrecycleviewtwo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import java.util.ArrayList;
import java.util.List;

public class HomeActivity extends AppCompatActivity {

    private List<String> _listData;
    private RecyclerView rv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        initData();

        rv = (RecyclerView) findViewById(R.id.rv);
        /*
        * 瀑布流的控件
        * 如果是横向滚动的话需要注意高度
        * */
        rv.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL));
        //设置系统默认实现的动画
        rv.setItemAnimator(new DefaultItemAnimator());
        rv.setAdapter(new HomeAdapter(this, this._listData));
    }

    /*
    * 初始化要加载的数据
    * */
    private void initData() {
        _listData = new ArrayList<String>();
        for (int i = 'A'; i < 'z'; i++) {
            char c = (char) i;
            this._listData.add("" + c);
        }
    }
}
